#include "StdAfx.h"
#include "Subject.h"

#include <iostream>

using namespace std;

Subject::Subject(void)
{
}


void Subject::registerObserver(Observer* observer)
{
	observers.push_back(observer);
}

void Subject::unregisterObserver(Observer* observer)
{
	for(int i = 0; i < observers.size(); i++)
	{
		if(observers[i] == observer)
		{
			//observers[i];
			observers.erase(observers.begin()+i);
		}
	}
}

void Subject::notifyObservers()
{
	for(int i = 0; i < observers.size(); i++)
	{
		//cout << "notify " << endl;
		observers[i]->notify();
	}
}

Subject::~Subject(void)
{
	observers.clear();
}
